/*
 * @Author: Aro
 * @Date: 2024-01-29 09:10:06
 */
import 'package:flutter/material.dart';
import 'package:flutter_baseui/routers/fluro_navigator.dart';
import 'package:flutter_baseui/routers/screen_routers/router_screen_router.dart';
import 'package:flutter_baseui/views/router_screen/demo/model/complex_params_model.dart';
import 'package:flutter_baseui/views/router_screen/demo/model/params_back_model.dart';
import 'package:flutter_baseui/widgets/model/icon_event_model.dart';
import 'package:flutter_baseui/widgets/nav_bar_kit.dart';

class RouterScreen extends StatefulWidget {
  const RouterScreen({super.key});

  @override
  State<RouterScreen> createState() => _RouterScreenState();
}

class _RouterScreenState extends State<RouterScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFEDF0F2),
      body: Column(
        children: [
          NavBarKit(
            title: '路由跳转演示',
            leftConfig: IconEventModel(
              icon: const Icon(Icons.arrow_back),
              onTap: () {
                FluroNaviagtor.goBack(context);
              },
            ),
          ),
          Expanded(
            child: Column(
              children: [
                ElevatedButton(
                  child: const Text('通过url地址传递参数'),
                  onPressed: () {
                    /**
                     * 原始的url xxx?userId=mytestuserid=6666&userName=Aro
                     * 路由转换后的url  {userId: [mytestuserid=6666], userName: [Aro]}
                     * 获取方式 params['userId']!.first
                     */
                    FluroNaviagtor.pushResult(
                      context,
                      '${RouterScreenRouter.routerParamsPage}?userId=mytestuserid=6666&userName=Aro',
                      (Object result) {
                        final data = result as ParamsBackModel;
                        debugPrint('路由返回来的参数=====${data.phone}, ${data.time}');
                      },
                    );
                  },
                ),
                ElevatedButton(
                  child: const Text('通过arguments传递复杂的参数'),
                  onPressed: () {
                    FluroNaviagtor.push(
                      context,
                      RouterScreenRouter.routerComplexParamsPage,
                      arguments: const ComplexParamsModel(
                        username: 'zhouhongyu',
                        id: '950701',
                      ),
                    );
                  },
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
